package com.song.tools.songtest.controller;

import cn.dev33.satoken.annotation.SaCheckOr;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.song.tools.core.beans.response.ResultVo;
import com.song.tools.log.systemlog.annotation.SysLog;
import com.song.tools.mvc.controller.SuperCrudController;
import com.song.tools.songtest.beans.request.SysRoleUserGrantRolesRequest;
import com.song.tools.songtest.beans.request.SysRoleUserQueryRequest;
import com.song.tools.songtest.beans.request.SysRoleUserSaveRequest;
import com.song.tools.songtest.beans.request.SysRoleUserUpdateRequest;
import com.song.tools.songtest.beans.response.*;
import com.song.tools.songtest.service.SysRoleUserService;
import com.song.tools.songtest.trigger.SysUserTriggerManager;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * <p>
 * 用户角色关系表 前端控制器
 * </p>
 *
 * @author song tools
 * @since 2024-07-12
 */
@Tag(name = "用户角色关系表前端控制器")
@RestController
@RequestMapping("/sysRoleUser")
public class SysRoleUserController extends SuperCrudController<SysRoleUserService, SysRoleUserQueryRequest, SysRoleUserQueryResponse, SysRoleUserSaveRequest, SysRoleUserSaveResponse, SysRoleUserUpdateRequest, SysRoleUserUpdateResponse, Long, SysRoleUserDeleteResponse> {


    /**
     * 为用户设置角色
     *
     * @param request 请求
     * @return 响应
     */
    @SaCheckOr(
            role = {@SaCheckRole("manager")}
    )
    @Operation(summary = "为用户设置角色")
    @PostMapping("/grantRolesForUser")
    @SysLog("为用户设置角色")
    public ResultVo<SysRoleUserGrantRolesResponse> grantRolesForUser(@Valid @RequestBody SysRoleUserGrantRolesRequest request) {
        return ResultVo.success(SysUserTriggerManager.grantRolesForUser(request));
    }
}
